package com.example.juc;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class JUCStream {
    public static void main(String[] args) {
        ArrayList<Student> students = new ArrayList<>();
        students.add(new Student("a",1,21));
        students.add(new Student("b",2,22));
        students.add(new Student("c",3,23));
        students.add(new Student("d",4,24));
        students.add(new Student("e",5,25));
        students.add(new Student("f",6,26));
        Stream<Student> studentStream = students.stream().filter(s -> {
            if (s.getId() % 2 == 0 && s.getAge() > 23) {
                s.getName().toUpperCase(Locale.ROOT);
                return true;
            }
            return false;
        });
        List<Student> studentList = studentStream.collect(Collectors.toList());
        Stream<Student> sorted = studentList.stream().sorted((s1, s2) -> {
            int i = s1.getName().compareTo(s2.getName());
            return i;
        }).limit(1);
       sorted.forEach(stus->{
           System.out.println(stus.toString());
       });

    }
}
